package com.ncloud.crm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.*;

import com.ncloud.crm.entity.BsAttr;

/**
 * Created by shiqiang on 2017/4/11.
 */
@Mapper
public interface BsAttrMapper {
    @Select(value = { "select * from bs_attr where id = #{id}" })
    @Results({ @Result(column = "id", property = "id"),
            @Result(column = "attr_type", property = "attrType"),@Result(column = "attr_code", property = "attrCode"),
            @Result(column="attr_value",property="attrValue"),@Result(column="begin_date",property="beginDate"),
            @Result(column="end_date",property="endDate"),@Result(column="attr_id",property="attrId")})
    public List<BsAttr> getAttrByOrderId(Long orderId);
    @Insert(value = "insert into bs_attr(id,attr_type,attr_code,attr_value,begin_date,end_date,attr_id) " +
            "values(#{id},#{attrType},#{attrCode},#{attrValue},#{beginDate},#{endDate},#{attrId})")
    public int insertOrderAttr(BsAttr bsAttr);

    @Select(value = { "select * from bs_attr where 1=1 and id = #{id} and attr_type=#{attrType}" +
            " and attr_code=#{attrCode} and now() between begin_date and end_date " })
    @Results({ @Result(column = "id", property = "id"), @Result(column = "attr_id", property = "attrId"),
            @Result(column = "attr_type", property = "attrType"),@Result(column = "attr_value", property = "attrValue"),
            @Result(column = "attr_code", property = "attrCode"),@Result(column = "end_date", property = "endDate"),
            @Result(column="begin_date",property="beginDate")})
    public BsAttr getValidAttrInfo(BsAttr bsAttr);
    @Update("update bs_attr set attr_value=#{attrValue} where 1=1 and id = #{id} and attr_type=#{attrType} " +
            " and attr_id=#{attrId} and attr_code=#{attrCode}  and now() between begin_date and end_date ")
    int updateAttrValue(BsAttr bsAttr);
}
